package com.wyz.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wyz.dto.UpdateScoreDto;
import com.wyz.entity.ScoreEntity;
import com.wyz.mapper.ScoreMapper;
import com.wyz.vo.StudentScoreVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ScoreService {
    @Resource
    private ScoreMapper scoreMapper;
    //分页查询学生成绩信息
    public IPage<StudentScoreVo> getStudentScoreListByPage(int currentPage) {
        IPage<StudentScoreVo> page = new Page<>(currentPage,5);
        IPage<StudentScoreVo> studentScoreListPage = scoreMapper.selectPageByStudentId(page,null);
        return studentScoreListPage;
    }

//通过学生ID插入成绩
    public Boolean addScore(ScoreEntity scoreEntity) {
       return scoreMapper.updateById(scoreEntity)>0;
   }

    //修改成绩通过学生ID
    public Boolean updateScore( UpdateScoreDto updateScoreDto) {
        //先判断学生是否存在
        return scoreMapper.updateScoreByStudentId(updateScoreDto.getStudentId(), updateScoreDto.getScore());
        }


//通过学生ID查询成绩
    public List<StudentScoreVo> getScoresByStudentId(Integer studentId) {

        return scoreMapper.findScoresByStudentId(studentId);
    }
    //通过课程ID查询成绩
    public List<StudentScoreVo> getScoresByCourseId(Integer courseId) {
        return scoreMapper.getScoresByCourseId(courseId);
    }
    //通过学生姓名模糊查询
    public List<StudentScoreVo> getScoresByStudentName(String name) {
        return scoreMapper.findScoresByStudentName(name);
    }

    public List<StudentScoreVo> getStudentScoreList() {
        return scoreMapper.findAllStudentScores();
    }

}

